package com.wft;

import java.util.Arrays;

public class Solution754 {
    public static void main(String[] args) {
        int[] a = {3,1,4,2};
        System.out.println(Arrays.toString(sortArrayByParityII(a)));
    }

    public static int[] sortArrayByParityII(int[] A) {
        if(A == null || A.length == 0){
            return A;
        }

        int tempVal = 0;
        int tempIndex = 0;
        for(int i = 0;i < A.length; i++){
            tempIndex = i;
            if(i%2==0){
                while(A[i]%2 != 0){
                    tempVal = A[i];
                    A[i] = A[tempIndex + 1];
                    A[tempIndex + 1] = tempVal;

                    tempIndex++;
                }
            }else{
                while(A[i]%2 != 1){
                    tempVal = A[i];
                    A[i] = A[tempIndex + 1];
                    A[tempIndex + 1] = tempVal;

                    tempIndex++;
                }
            }
        }
        return A;
    }
}
